/***************************************************************************** 
* File Name: button.c
* 
* Description:
* This file contains API for reading the button status
* 
* Note:
* Defining DISABLE_BUTTON in platform.h to disable button module
* Defining DISABLE_KEYBOARD_INTER_COLUMN_BUTTON in platform.h to disable button between 
* the keyboard rows 
* 
* Owner: MRAO
* 
* Related Document:
* cy_pins component datasheet
* 
* Hardware Dependency:
* Buttons hardware
* 
* Code Tested With:
* 1. PSoC Creator 3.1 
* 2. ARM GCC 4.8.4
*******************************************************************************/
#include "button.h"

/* Macro used for different states of the motion sensor button */
#define BUTTON_STATE_NONE                   0x0
#define BUTTON_STATE_SINGLE_PRESSED         0x1
#define BUTTON_STATE_SINGLE_RELEASED        0x2
#define BUTTON_STATE_DOUBLE_PRESSED         0x3
#define BUTTON_STATE_DOUBLE_RELEASED        0x4

#ifndef DISABLE_BUTTON
/* To indicate the status of the button (pressed / released) */
static uint8 buttonStatus;

/* Variable to keep track of the device state */
static bool isDeviceActive; 
static bool isFirstTimeDetection;

#if !defined(DISABLE_KEYBOARD) && !defined(DISABLE_KEYBOARD_INTER_COLUMN_BUTTON)
static uint8 buttonState;
static uint32 repeatTimeStamp;
#endif  /* DISABLE_KEYBOARD  || DISABLE_KEYBOARD_INTER_COLUMN_BUTTON */

void Button_Init(void) {
    // Initialization code here
}

uint8 Button_Poll(void) {
    // Polling logic here
    return buttonStatus;
}

void Button_Set_State(Device_State state) {
    // Set device state logic here
}

ReportType Button_Get_Report(Report *report) {
    // Report generation logic here
    return NO_REPORT;
}

bool Button_IsActive(void) {
    // Check if button is active logic here
    return false;
}

void Button_Stop(void) {
    // Stop button module logic here
}

// 创建ButtonModule的实例，命名为button
ButtonModule button = {
    .Init = Button_Init,
    .Poll = Button_Poll,
    .Set_State = Button_Set_State,
    .Get_Report = Button_Get_Report,
    .IsActive = Button_IsActive,
    .Stop = Button_Stop
};

#else

// 创建ButtonModule的实例，命名为button
ButtonModule button = {
    .Init = Button_Init,
    .Poll = Button_Poll,
    .Set_State = Button_Set_State,
    .Get_Report = Button_Get_Report,
    .IsActive = Button_IsActive,
    .Stop = Button_Stop
};

#endif /* DISABLE_BUTTON */